//基础数据-
import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal} from 'antd';
import UpdateGroupPage from './update'
import {fetchData} from '../../../components/AjaxConsumer'
 
export default class ListGroupPage extends Component{
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: []
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'edit',
                iconClass: 'cellEdit'
            }, {
                handleName: 'delete',
                iconClass: 'cellDele'
            }, {
                handleName: 'assignUser',
                iconClass: 'cellRole'
            }
        ];
        // this.state={
        //     loading: false,
        //     visible: false,
        //     addFlag: false,
        //     formData:{},
        //     submitUrl:'',
        // };
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'add',
                showName: '新增',
                iconClass: 'plus'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete'
            }
        ];
 
        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'ListGroupColumnConfig',
            data: [
                {
                    showName: 'factoryGroupId',
                    columnName: 'factoryGroupId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '工厂组编码',
                    columnName: 'groupCode'
                },{
                    showName: '工厂组名称',
                    columnName: 'groupName'
                },{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate'
                },{
                    showName: '最后修改人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '最后修改时间',
                    columnName: 'gmtModified'
                },{
                    showName: '激活标记',
                    columnName: 'activeFlag',
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'0',
                            optionShow:'否'
                        },{
                            optionKey:'1',
                            optionShow:'是'
                        }
                    ]
                },{
                    showName: '备注',
                    columnName: 'remark'
                }
            ]
        };
 
        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                name:'activeFlag',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'否'
                    },{
                        optionKey:'1',
                        optionShow:'是'
                    }
                ]
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'gmtCreateMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax', 
                minName:'gmtModifiedMin'
            }
        ];
 
    }
    // 行操作
    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if(strHandles === 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }else if(strHandles === 'add'){
            this.addHandle();
        }
    }
 
    //添加
    addHandle = () => {
        console.log("====执行了新增用户操作====");
        this.refs.updateGroup.getFormData[1].disable = false;
        this.refs.updateGroup.addHandle();
    }
    editHandle = (rowObj) => {
        console.log("====执行了修改操作====");
        // 只能选择一条限制
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else {
            this.refs.updateGroup.getFormData[1].disable = true;
            this.refs.updateGroup.editHandle(rowObj[0].data)
        }
 
    }
 
    deleteHandle = (rowObj) => {
        console.log("=======执行了删除操作====");
        // 只能选择一条限制
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else {
            this.refs.updateGroup.deleteHandle(rowObj[0].data)
        }
 
    }
        //刷新List列表
        refreshHandle = () => {
            console.log("刷新List列表")
            this.refs.listFactoryGroup.refreshHandle();
        }
 
        componentDidMount() {
            const dicType = 'active_flag';
            const options= {
                url: '/base/dic/get/' + dicType,
                type: 'get',
                condition:{}
            };
            //先写死，后面再改
            //fetchData(this, options, this.dicInitCallBackHandle);
        }
 
        render() {
            //当左侧隐藏时，列表宽度加上左侧的宽度，
            //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
            //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
            let isHideLeft = this.props.isHideLeft;
    
            return(
                <div>
                    <ListBox
                        ref = 'listFactoryGroup'
                        title="工厂组管理"
                        isHideLeft={isHideLeft}
                        tableColumnData = {this.tableColumn}
                        searchComponentData={this.searchComponentData}
                        url = '/base/factory/group/list'
                        rowHandles = {this.rowHandles}
                        rowOperation = {this.rowOperation}
                        headerOperation = {this.headerOperation}
                        isRowSingle = "true"
                    />
                    {/* <Modal
                        style={{top: '20px'}}
                        visible={this.state.visible}
                        title="工厂组维护"
                        onOk={this.handleOk}
                        onCancel={this.handleCancel}
                        width={'850px'}
                        footer=''
                        maskClosable={false}>
                        <ListGroupFrom
                            onCancel={this.handleCancel}
                            ref="form"
                            submitUrl={this.state.submitUrl}
                            formData={this.state.formData}
                            init={this.state.visible}
                            refreshHandle={this.refreshHandle}
                        />
                    </Modal> */}
                    <UpdateGroupPage
                        ref="updateGroup"
                        refreshHandle = {this.refreshHandle}
                />
                </div>
            )
        }
}